package dyyx.file;

import java.io.File;

import dyyx.util.CommUtil;

public abstract class FileScanUtil {

	public static void doScan(File file, ScanContext context) throws Exception {
		if (file == null || context == null) {
			return;
		}

		if (CommUtil.isSymlink(file)) {
			return;
		}

		if (file.isDirectory()) {

			File[] fs = file.listFiles();

			if (fs == null || fs.length <= 0) {
				return;
			}

			for (File f : fs) {

				if (CommUtil.isSymlink(f)) {
					return;
				}

				if (f.isDirectory()) {
					doScan(f, context);
					continue;
				}

				if (context.handler != null) {
					context.handler.run(f, context);
				}

			}

			return;

		}

		if (context.handler != null) {
			context.handler.run(file, context);
		}

	}

}
